package com.aha.secondchapter.second;

/**
 * 自定义栈
 * Created by wangxin on 2015/10/31.
 */
public class MyStack {
    private int top;
    private int[] data;
    public MyStack(int[] data){
        this.data = data;
        this.top = -1;
    }

    public boolean isEmpty(){
        return this.top ==-1;
    }

    /**
     * 出栈
     * @return
     */
    public int pop(){
        int topData = data[top];
        data[top] = 0;
        top--;
        return topData;
    }

    /**
     * 入栈
     * @param i
     */
    public void push(int i){
        data[++top] = i;
    }

    /**
     * 获取栈内所有元素
     * @return
     */
    public int[] getData() {
        return data;
    }

    /**
     * 获取栈顶元素
     * @return
     */
    public int getTopData(){
        return data[top];
    }
    public void setData(int[] data) {
        this.data = data;
    }

    public int getTop() {
        return top;
    }

    public void setTop(int top) {
        this.top = top;
    }
}
